import { getMsgList } from '@/api/msg_session'

export default {
  namespaced: true,
  state: {
    showMsgList: null,
    currentTime: 0
  },

  mutations: {
    setMsgList (state, obj) {
      state.showMsgList = JSON.stringify(obj)
    },
    addMsg (state, obj) {
      const newObj = state.showMsgList ? JSON.parse(state.showMsgList) : []
      newObj.push(obj)
      state.showMsgList = JSON.stringify(newObj)
    }
  },

  actions: {
    async getMsgList (context, sessionId) {
      const res = await getMsgList(sessionId)
      context.commit('setMsgList', res.data)
    }
  },

  getters: {
    showMsgList (state) {
      return state.showMsgList ? JSON.parse(state.showMsgList) : []
    }
  }
}
